package com.anjubao.parking.municipal.common.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;

@Configuration
@MapperScan(basePackages = "com.anjubao.parking.municipal.*")
public class MybatisPlusProperties {
	/** 询性能优化拦截器-开关 true:打开,false:关闭 **/
	@Value("${mybatis-plus.performance.switch:false}")
	private Boolean performanceSwitch;
	@Value("${mybatis-plus.performance.max-time:1000}")
	private Integer performanceMaxTime;

	// plus 的性能优化日志输出，不要就注释掉
	@Bean
	public PerformanceInterceptor initPerformanceInterceptor() {
		PerformanceInterceptor performanceInterceptor = null;
		if (performanceSwitch) {
			performanceInterceptor = new PerformanceInterceptor();
			/* <!-- SQL 执行性能分析，开发环境使用，线上不推荐。 maxTime 指的是 sql 最大执行时长 --> */
			performanceInterceptor.setMaxTime(performanceMaxTime);
			/* <!--SQL是否格式化 默认false--> */
			performanceInterceptor.setFormat(true);
		}
		return performanceInterceptor;
	}

	// mybatis-plus分页插件
	@Bean
	public PaginationInterceptor initPaginationInterceptor() {
		PaginationInterceptor page = new PaginationInterceptor();
		// page.setDialectType("mysql");
		return page;
	}

}
